### Create Variables

gen marta1=0
replace marta1=1 if p64==9
replace marta1=. if p63<3

gen serra1=0
replace serra1=1 if p64==7
replace serra1=. if p63<3

gen rm=0
replace rm=1 if p9502==1
replace cct=. if missing(p9406)

gen bf=0
replace bf=1 if p9501==1
replace bf=. if missing(p9406)

gen rc=0
replace rc=1 if p9503==1
replace rc=. if missing(p9406)

gen be=0
replace be=1 if p9504==1
replace be=. if missing(p9406)

gen cct=0
replace cct=1 if p9501==1
replace cct=1 if p9503==1
replace cct=1 if p9504==1
replace cct=. if missing(p9406)

gen negro=0
replace negro=1 if a11==2
replace negro=1 if a11==3
replace negro=. if missing(a11)

gen male=0
replace male=1 if a6==1
replace male=. if missing(a6)

gen employed=0
replace employed=1 if p82<9
replace employed=. if missing(p82)

gen upper=0
replace upper=1 if a4==2
replace upper=. if missing(a4)

gen peripheral=0
replace peripheral=1 if a5==3
replace peripheral=. if missing(a5)

gen intermediate=0
replace intermediate=1 if a5==1
replace intermediate=. if missing(a5)


### Estimate Models for Marta (1st round)

# Model 1
logit marta1 rm cct employed upper male negro peripheral intermediate [pweight=peso]

# Model 2
logit marta1 rm bf employed upper male negro peripheral intermediate [pweight=peso]

# Model 3
logit marta1 i.rm##i.cct employed upper male negro peripheral intermediate [pweight=peso]
margins, dydx(rm) at(cct==1)
margins, dydx(rm) at(cct==0)
margins, dydx(cct) at(rm==1)
margins, dydx(cct) at(rm==0)

tab rm if !missing(marta1)
tab cct if !missing(marta1)

# Model 4
logit marta1 i.rm##i.bf employed upper male negro peripheral intermediate [pweight=peso]
margins, dydx(rm) at(bf==1)
margins, dydx(rm) at(bf==0)
margins, dydx(bf) at(rm==1)
margins, dydx(bf) at(rm==0)

tab bf if !missing(marta1)

### Estimate Models for Serra (1st round)

# Model 1
logit serra1 rm cct employed upper male negro peripheral intermediate [pweight=peso]

# Model 2
logit serra1 rm rc employed upper male negro peripheral intermediate [pweight=peso]

# Model 3
logit serra1 i.rm##i.cct employed upper male negro peripheral intermediate [pweight=peso]
margins, dydx(rm) at(cct==1)
margins, dydx(rm) at(cct==0)
margins, dydx(cct) at(rm==1)
margins, dydx(cct) at(rm==0)

tab cct if !missing(serra1)
tab rm if !missing(serra1)

# Model 4
logit serra1 i.rm##i.bf employed upper male negro peripheral intermediate [pweight=peso]
margins, dydx(rm) at(bf==1)
margins, dydx(rm) at(bf==0)
margins, dydx(bf) at(rm==1)
margins, dydx(bf) at(rm==0)

tab bf if !missing(serra1)
